/*
 * @Author: 丁平|1572804782@qq.com(dingping)
 * @Date: 2022-02-12
 * @LastEditors: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @LastEditTime: 2022-07-27 10:44:04
 * @Description: 
 * @Administrator: 丁平|1572804782@qq.com(dingping)
 * @Copyright: 1.0.5
 */

import workreportmainApi from '../../../../../../public/js/common/api/mybusiness/workreport/workreportmain.api.js'
import { uploadFile, requestFilePath, publicFileDraw, sliceFileName } from "../../../../../../public/js/common/api/file-request.js";
import ContactAPI from '../../../../../../public/js/common/api/mybusiness/workreport/reportcontact.api.js';
// Utils.NameSpace('SN.CptvPlf.Bid.Wxcontact');
/**
 *@file填写工作汇报
 *@Date :2022-02-16 10:05:41
 *@create周润玉
*/
(function (window, document, $) {
    'use strict';
    let _vm;
    let uploader = null;
    let staffJson = SN.H5.WorkReportMain.Employee;
    /**
     * 汇报对象变量
     */
    const _page = {
        searchInfo: "",
        pageSize: 50,
        pageIndex: 0,
        status: "true",
        totalPages: -1
    };
    let employeesList = [];// 人员
    let checkboxList = [];// 选中人员ID
    let checkEmploy = [];// 提交数据
    let reportVal = "1"// 汇报类型
    let reportData = {}// 存储汇报类型和开始结束时间

    $(function () {

        _vm = new Vue({
            el: "#main-mine-data-submit",
            data() {
                return {
                    formObject: {},
                    modalData: {
                        bidResultEntryId: "",
                        bidResultId: "",
                    },
                    //expectedTimeLoading: '',
                    uploadCount: 0,
                    wordNumber: 0,
                    images: [],///处理weui自带上传插件回显重新上传时的问题
                    contents: '',
                    plans: "",
                    isNothing: true,
                    // quickQuery: '',
                    page: { ..._page },
                    ischeckboxNum: 0
                }
            },
            methods: {
                submit: function () {

                },
                truckLoadingTime: function (param) {
                    // 保存当前的滚动距离
                    scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    // 设置 fixed 布局
                    document.body.style.position = 'fixed';
                    document.body.style.height = '100%';
                    document.body.style.width = '100%';

                    // $("#datetime-picker").datetimePicker();
                    // isWhichTime()
                }
            },
        });

        defaultWorkEmp();
        uploadInit();
        initCommand();
        datetimePickerInit();
        $(document).on('mousedown', '.clearContent', function (e) {
            e.target.style.fontSize = '16px'
        });
        $(document).on('focus', '.clearContent', function (e) {
            e.target.style.fontSize = '16px'
        });

    });

    const defaultWorkEmp = () => {
        //查询员工上次所选汇报对象
        workreportmainApi.getNextEmployees(staffJson.id).then(res => {
            //checkboxList=res;
            checkEmploy = res;
            checkboxList = res.map(item => item.id);
            _employeesData(res);
        });
    }

    /**
    * 汇报对象 初始化
    */
    const _employeesData = () => {
        $('#subEmployees').text(`确定(${checkboxList.length})`);
        $("#choose").text(`已选择:${checkboxList.length} 人`);
        weui.searchBar('#searchInput');
        //TODO : 员工上拉加载
        $("#iscroll").infinite().on("infinite", function () {
            let _data = _vm._data.page;
            if (_data.pageIndex == _data.totalPages) return;
            let self = this;
            if (self.loading) return;
            self.loading = true;
            setTimeout(function () {
                queryEmployeesList();
                self.loading = false;
            }, 500);   //模拟延迟
        });
        $("#searchdiv form").submit(function () {
            _mainSearch();
            return false;
        }).on("input propertychange", Utils.throttle(_mainSearch, 500));
        search();
    }

    ///输入框
    const _mainSearch = function () {
        let _page = { "searchInfo": $('#searchInput').val(), "pageIndex": 0, "totalPages": -1, "pageSize": 50, "status": true };
        _vm._data.page = Object.assign(_vm._data.page, _page);
        $("#content").empty();
        queryEmployeesList();
    };

    const _clearInput = () => {
        $('#content').empty();
        checkboxList = [];
        $('#choose').text('已选择0人');
        $('#subEmployees').text('确定');
    }

    //TODO : 命令初始化
    //Date :2022-02-16 10:17:14
    //create周润玉   
    const initCommand = () => {
        $('#statDate').val(moment(new Date()).format('YYYY-MM-DD'));
        $('#endDate').val(moment(new Date()).format('YYYY-MM-DD'));

        //TODO : 工作汇报提交
        //Date :2022-02-16 10:17:29
        //create周润玉  
        $('#reportSubmit').on('click', async function () {
            // let type = $('#reportSelect').val();
            let { start, end, type } = reportData;
            switch (type.toString()) {
                case '1'://日报
                    if (!Utils.IsNotNull($('#todayContent').val())) return $.toptip('今日工作不能为空', 'warning');
                    break;
                case '2'://周报
                    if (!Utils.IsNotNull($('#todayContent').val())) return $.toptip('本周工作不能为空', 'warning');
                    break;
                case '3'://月报
                    if (!Utils.IsNotNull($('#todayContent').val())) return $.toptip('本月工作不能为空', 'warning');
                    break;
                case '4'://汇报
                    if (!Utils.IsNotNull($('#todayContent').val())) return $.toptip('工作内容不能为空', 'warning');
                    break;
            }
            let _atteValue = [];
            let loadFiles = $("#uploaderFiles li");
            $.each(loadFiles, function (i, v) {
                let data = v.dataset;
                let itense = { "id": data.imageId, "name": data.name, "suffix": data.suffix };
                _atteValue.push(itense);
            });
            if (!Utils.IsNotNull(checkEmploy)) {
                return $.toptip('请选择汇报对象', 'warning');
            }
            // 增加判断
            // let _employ = await workreportmainApi.getLoginUserToStaff();
            // let empqueryJSon = {
            //     searchInfo: _employ?.numCode,
            //     pageIndex: 0,
            //     pageSize: 10,
            //     status: true
            // }
            // let empleInfo = await ContactAPI.queryEmployees(empqueryJSon)
            // let empleList = empleInfo.items
            // let flag = empleList.some(item => item.id == _employ?.id && item.name == _employ?.name)
            // if (flag == false) {
            //     return $.toptip(`关联员工有误，请联系管理员!`, 'warning');
            // }
            let data = {
                "reportStartDate": start,
                "reportEndDate": end,
                "reportType": type,
                "reporterId": staffJson.id,
                "reporterNumCode": staffJson.numCode,
                "reporterName": staffJson.name,
                "contents": $('#todayContent').val(),
                "plans": $('#tomorrowPlan').val(),
                "recipients": checkEmploy,
                "attachments": _atteValue
            }
            let ago = new Date();
            ago.setDate(ago.getDate() - 3);//天数-3
            let agond = ago.getFullYear() + "-" + (ago.getMonth() + 1) + "-" + ago.getDate();//新日期
            // if (new Date(moment(agond).format('YYYY-MM-DD')).getTime() > new Date($('#changeTime').val()).getTime()) {
            //     return $.toptip('只可补前三天的汇报', 'warning');
            // }
            workreportmainApi.addWkrptsBill(data).then(res => {
                if (res.isSucceed) {
                    $('#changeTime').val(moment(new Date()).format('YYYY-MM-DD'));
                    _clearInput();
                    //setTimeout(() => { window.history.back(-1); }, 250);
                    $('.clearContent').each(function () {
                        $(this).val("").trigger('change');
                    })
                    $('#uploaderFiles .weui-uploader__file').each(function () {
                        //$(this).remove();
                        //删除图片的回调
                        let _id = $(this).attr('data-id');
                        _vm.images = _vm.images.filter(item => item.id != _id);
                        _vm.uploadCount = --_vm.uploadCount;
                        $(this).remove();
                    });
                    $('.weui-uploader__input-box').css('display', 'block');
                    defaultWorkEmp();
                    SN.H5.WorkReportMain.LookReportList();
                    $.toast("提交成功");
                    $("#reportSelect").val(1).change();
                    location.reload('../../../../../html/features/biz/workreport/lookreport/lookreport.html');
                }
            });
        });

        //返回首页
        $('#returnMain').on('click', function () {
            location.href = '../../main.html'
        })

        //点击汇报对象选择
        $(".reportLead").on('click', function () {
            $("#report-contact").popup();
            $("#content").empty();
            refreshQuery();
        });
        $(document).on('click', '#iscroll .weui-check__label', function (event) { // 搜索回车事件
            // event.stopPropagation();   //表示阻止向父元素冒泡
            event.preventDefault();     //阻止 方法阻止元素发生默认的行为（例如，当点击提交按钮时阻止对表单的提交或者a标签）
            let isChecked = $(this).find("input[type='checkbox']").is(':checked')
            $(this).find("input[type='checkbox']").prop("checked", !isChecked);
            if (!isChecked == true && checkboxList.includes($(this).data("id")) == false) {
                checkboxList.push($(this).data("id"));
            } else {
                checkboxList.splice(checkboxList.indexOf($(this).data("id")), 1);
            }
            $('#subEmployees').text(`确定(${checkboxList.length})`);
            $("#choose").text(`已选择:${checkboxList.length} 人`);
        });
        // 选择推送对象完成时
        $("#subEmployees").on('click', function () {
            let subData = [...checkboxList.map(item => { return [...employeesList, ...checkEmploy].find(item1 => item1.id == item); })] || [];
            checkEmploy = subData;
            $.closePopup();
            $('#searchInput').val("");
            $('#searchBar').removeClass("weui-search-bar_focusing");
        });
        // 汇报人取消按钮
        $("#cancelSub").on('click', function () {
            let checkHistory = [...checkEmploy.map(item => { return item.id })] || [];// 点取消时的上一次数据
            checkboxList = checkHistory;// 上一次点 确定的数据  赋值给  选中的数据
            $('#subEmployees').text(`确定(${checkboxList.length})`);
            $("#choose").text(`已选择:${checkboxList.length} 人`);
            $.closePopup();
            $('#searchInput').val("");
            $('#searchBar').removeClass("weui-search-bar_focusing");
        });
    };

    //TODO : 日期初始化
    //Date :2022-02-16 10:17:55
    //create周润玉  
    const datetimePickerInit = () => {
        $('#changeTime').val(moment(new Date()).format('YYYY-MM-DD'));
        //日报默认数据
        reportData = { start: moment(new Date()).format('YYYY-MM-DD'), end: moment(new Date()).format('YYYY-MM-DD'), type: 1 }
        $('#pickData').on('click', function () {
            pick();
        });
        $('#reportSelect').on('change', function () {
            let that = $(this);
            reportVal = that.val();
            let contentTitle = $("#contentTitle"), planTitle = $("#planTitle"), tomorrowPlan = $("#tomorrowPlan"), todayContent = $("#todayContent")
            let nowDate = (new Date()).Format("yyyy-MM-dd")

            let _titleContent = {// 需要修改的标题 或者 文本域的提示内容
                1: { content: "今日工作内容", plan: "明日计划", setTime: nowDate, _reportData: { start: nowDate, end: nowDate, type: reportVal } },
                2: { content: "本周工作内容", plan: "下周计划", setTime: `${nowDate}(第 ${moment(nowDate, "YYYY-MM-DD").isoWeek()} 周)`, _reportData: { start: GetMonday(nowDate), end: nowDate, type: reportVal } },
                3: { content: "本月工作内容", plan: "下月计划", setTime: timeFormat(nowDate, false), _reportData: { start: getMonthTime(nowDate).state, end: returnEndTime(nowDate), type: reportVal } },
                4: { content: "工作内容", plan: "下阶段计划", setTime: `${nowDate} 至 ${nowDate}`, _reportData: { start: nowDate, end: nowDate, type: reportVal } }
            }
            let { content, plan, setTime, _reportData } = _titleContent[reportVal];
            contentTitle.html(`${content}<span class="red-900">&nbsp;*</span>`)
            planTitle.text(plan)
            todayContent.attr("placeholder", `请输入${content}...`)
            tomorrowPlan.attr("placeholder", `请输入${plan}...`)
            $('#changeTime').val(setTime);//设置
            reportData = _reportData;//给默认日期
        });

    }

    const returnEndTime = (times) => {//  判断是否是本月 是 取当天时间  否取选择月的最后一天
        let nowDate = (new Date()).Format("yyyy-MM-dd")
        let selectMonth = timeFormat(times, false), end = timeFormat(nowDate, false)
        return selectMonth == end ? timeFormat(nowDate) : getMonthTime(times).end
    }

    const pick = () => {
        let type = $('#reportSelect').val();
        switch (type) {
            case "3":
                weui.datePicker({
                    // start: 2020,
                    end: moment(new Date()).format('YYYY-MM-DD'),
                    defaultValue: [new Date().getFullYear(), new Date().getMonth() + 1],
                    depth: 2,// 显示多少列
                    // id: 'datePicker',
                    className: 'mypick',
                    onConfirm: function (result) {
                        let value = result[0].value + '-' + result[1].value;
                        $('#changeTime').val(value);
                        reportData = { start: value + `-01`, end: returnEndTime(value + `-01`), type: type }
                    }
                });
                break;
            default:
                weui.datePicker({
                    // start: `2020-01-01`,
                    defaultValue: (moment(new Date()).format('YYYY-MM-DD')).split('-'),
                    end: moment(new Date()).format('YYYY-MM-DD'),
                    className: 'mypick',
                    onConfirm: function (result) {
                        let type = $('#reportSelect').val();
                        let value = `${result[0].value}-${result[1].value}-${result[2].value}`;
                        if (type == "4") {
                            $('.mypick').on('animationend webkitAnimationEnd', function () {
                                timer222(value, type);
                            });
                            return true
                        }
                        let reportDate = type == "1" ? value : `${value}(第 ${moment(value, "YYYY-MM-DD").isoWeek()} 周)`;
                        $('#changeTime').val(reportDate);
                        reportData = {
                            start: type == "1" ? value : GetMonday(value),
                            end: value,
                            type: type
                        }
                    }
                });// 默认配置
                break;
        }
    }

    const timer222 = (val, type) => {
        weui.datePicker({
            start: val,
            defaultValue: (val.split("-")).map(Number),
            className: 'mypick',
            end: moment(new Date()).format('YYYY-MM-DD'),
            onConfirm: function (result) {
                let value = result[0].value + '-' + result[1].value + '-' + result[2].value;
                $('#changeTime').val(val + ' 至 ' + value);
                reportData = {
                    start: val,
                    end: value,
                    type: type
                }
            }
        });
    }

    //TODO : 附件上传
    //Date :2022-02-16 10:05:14
    //create周润玉
    const uploadInit = () => {
        weui.uploader('#uploader', {
            url: '',
            auto: false,
            type: 'file',
            compress: { isNoTCompress: true },
            onBeforeQueued: function (files) {
                // `this` 是轮询到的文件, `files` 是所有文件
                // if (["image/jpg", "image/jpeg", "image/png"].indexOf(this.type) < 0) {
                //     $.toptip('请上传图片', 'warning');
                //     return false; // 阻止文件添加
                // }
                if (this.size > 8 * 1024 * 1024) {
                    $.toptip('请上传不超过8M的文件', 'warning');
                    return false;
                }
                $.showLoading('上传中..');
                _vm.uploadCount = ++_vm.uploadCount;
                if (_vm.uploadCount == 3) {
                    $('.weui-uploader__input-box').hide();
                }
            },
            onQueued: function () {
                let formFile = new FormData();
                let upFiles = this;
                let file = publicFileDraw(this.name, _vm);
                if (file != false && file != undefined) {
                    formFile.append('apiobjfile', new window.File([this], file, { type: this.type }));
                    _uploadFileDraw(formFile, upFiles, _vm, file);
                }
                //确认提交
                $('.weui-dialog__btn').on('click', function () {
                    if ($(this)[0].innerHTML == '确认') {
                        let fileName = sliceFileName(upFiles);
                        let newfile = publicFileDraw(fileName, _vm);
                        if (newfile != false && newfile != undefined) {
                            formFile.append('apiobjfile', new window.File([upFiles], newfile, { type: upFiles.type }));
                            _uploadFileDraw(formFile, upFiles, _vm, newfile);
                        }
                    }
                });
                return true;
            }
        });
        $('#uploaderFiles').click(function (e) {
            let target = e.target;
            while (!target.classList.contains('weui-uploader__file') && target) {
                target = target.parentNode;
            }
            if (!target) return;
            //从图片对应的li标签中获得所需属性
            let gallery = weui.gallery($(target).attr('data-url'), {
                className: 'custom-name',
                onDelete: function () {
                    //删除图片的回调
                    $.confirm({
                        title: '删除提示',
                        text: '确定删除该图片？',
                        onOK: function () {
                            let _id = $(target).attr('data-id');
                            _vm.images = _vm.images.filter(item => item.id != _id);
                            _vm.uploadCount = --_vm.uploadCount;
                            target.remove();
                            gallery.hide();
                            // 添加3张后隐藏上传按钮
                            if (_vm.uploadCount == 3) {
                                $(".weui-uploader__input-box").hide();
                            } else {
                                $(".weui-uploader__input-box").show();
                            }
                        },
                        onCancel: function () {
                        }
                    });
                }
            });
        });
    }
    function unique(arr) {
        const res = new Map();
        return JSON.parse(JSON.stringify(arr)).filter((a) => !res.has(a.id) && res.set(a.id, 1))
    }

    /**
     *@file 附件上传
     *@Date :2022-07-26 11:23:57
     *@create周润玉
    */
    const _uploadFileDraw = (formFile, upFiles, _vm, newName) => {
        uploadFile(formFile).then(res => {
            if (res.isSucceed) {
                let _list = _vm.images;
                _list.push({
                    id: $("#uploaderFiles li").length,
                    imageId: res.data,
                    url: upFiles.url,
                    name: newName,
                    type: upFiles.name.split('.').pop().toLowerCase() //获取文件后缀名称
                });
                _vm.images = _list;
                $("#uploaderFiles li").each(function (i) {
                    $(this).attr('data-id', _vm.images[i].id);
                    $(this).attr('data-image-id', _vm.images[i].imageId);
                    $(this).attr('data-name', _vm.images[i].name);
                    $(this).attr('data-suffix', _vm.images[i].type);
                    if (["jpg", "jpeg", "png", 'gif'].indexOf(_vm.images[i].type) < 0) {
                        $(this).attr('data-url', '../../../../public/static/images/other/pic_default_uploader.png');
                        $(this).css({ 'background-image': `url(${'../../../../public/static/images/other/pic_default_uploader.png'})` });
                    } else {
                        $(this).attr('data-url', _vm.images[i].url);
                        $(this).css({ 'background-image': `url(${_vm.images[i].url})` });
                    }
                });
                $('.weui-uploader__file-content').hide();
                $('.weui-uploader__file').removeClass('weui-uploader__file_status');
            }
        }).catch(res => {
            $("#uploaderFiles li").eq($("#uploaderFiles li").length - 1).remove();
            _vm.uploadCount = --_vm.uploadCount;
            $.toptip(res.msg, 'error');
        }).finally(_ => {
            $.hideLoading();
            $.closeModal();
        });
    }

    /**
    * 汇报对象 操作
    */
    const queryEmployeesList = () => {
        let _data = _vm._data.page;
        let _list = [];
        ContactAPI.queryEmployees(_data).then(res => {
            let _page = {
                searchInfo: $('#searchInput').val(),
                status: true,
                pageSize: 50,
                pageIndex: _data.pageIndex + 1,
                totalPages: res.totalPages
            }
            _vm._data.page = Object.assign({}, _page);
            if (!Utils.IsNotNull($('#searchInput').val()) && _data.pageIndex == 0) {
                _list.push(...checkEmploy);
            }
            _list.push(...res.items);
            unique(_list).map(item => {
                let labhtml = `<label class="weui-cell weui-cell_active weui-check__label" for="${item.id}" data-id="${item.id}" id="lab_${item.id}">
                    <div class="weui-cell__hd">
                        <input type="checkbox" class="weui-check" name="checkbox1" id="${item.id}">
                        <i class="weui-icon-checked"></i>
                    </div>
                    <div class="weui-cell__hd" aria-hidden="true" style="position: relative;">
                        <img src="../../../../public/static/images/other/pic_default_headimg.png" alt="" class="headPortrait"
                            style="width: 50px;display: block;">
                    </div>
                    <div class="weui-cell__bd" aria-hidden="true">
                        <span class="lab_name">${item.name}</span>
                        <div class="demo_badge_desc lab_numCode">工号：${item.numCode}</div>
                    </div>
                </label>`
                $("#content").append(labhtml);
                // $(`#lab_${item.id}`).find("input[type='checkbox']").prop("checked", checkboxList.includes($(this).data("id")));
            });

            checkboxList.map(item => $(`#${item}`).prop("checked", true));
            // $("#content").empty().append(x);
            employeesList = [...employeesList, ...res.items];
        });
    }
    const search = () => {
        let $searchBar = $('#searchBar'),
            $searchResult = $('#searchResult'),
            $searchText = $('#searchText'),
            $searchInput = $('#searchInput'),
            $searchClear = $('#searchClear'),
            $searchForm = $('#searchForm'),
            $searchCancel = $('#searchCancel');

        function hideSearchResult() {
            $searchResult.hide();
            $searchForm.attr('aria-expanded', 'false');
            $searchInput.val('');
        }
        function cancelSearch() {
            hideSearchResult();
            $searchBar.removeClass('weui-search-bar_focusing');
            $searchText.show();
        }

        $searchText.on('click', function () {
            $searchBar.addClass('weui-search-bar_focusing');
            $searchInput.focus();
        });

        $searchInput
            .on('blur', function () {
                if (!this.value.length) cancelSearch();
            })
            .on('input', function () {

                if (this.value.length) {
                    $searchResult.show();
                    $searchForm.attr('aria-expanded', 'true');
                } else {
                    $("#content").empty();
                    //refreshQuery();
                    $searchResult.hide();
                    $searchForm.attr('aria-expanded', 'false');
                }
            })
            ;
        $searchClear.on('click', function () {
            hideSearchResult();
            $searchInput.focus();
            $("#content").empty();
            refreshQuery()
        });
        $searchCancel.on('click', function () {
            cancelSearch();
            $("#content").empty();
            refreshQuery();
            $searchInput.blur();
        });
    }
    const refreshQuery = () => {
        let _page = { "searchInfo": $('#searchInput').val(), "pageIndex": 0, "totalPages": -1, "pageSize": 50, "status": true };
        _vm._data.page = Object.assign(_vm._data.page, _page);
        queryEmployeesList();
    }

    function GetMonday(date) {// 获取周一
        var dd = new Date(date.replace(/-/g, "/"))// 解决IOS不支持YYYY-MM-DD格式
        var week = dd.getDay(); //获取时间的星期数
        var minus = week ? week - 1 : 6;
        dd.setDate(dd.getDate() - minus); //获取周一日期
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        return `${y}-${m}-${d}`;
    }

    // function GetSunday(date) {// 获取周天 原生专用
    //     var dd = new Date(date.replace(/-/g, "/"))// 解决IOS不支持YYYY-MM-DD格式
    //     var week = dd.getDay(); //获取时间的星期数
    //     var minus = week ? week - 1 : 6;
    //     dd.setDate(dd.getDate() - minus);//获取周一日期
    //     dd.setDate(dd.getDate() + 6)//加6得到周日日期
    //     var y = dd.getFullYear();
    //     var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
    //     var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    //     return `${y}-${m}-${d}`;
    // }

    function getMonthTime(date) {// 获取本月开始时间和结束时间IOS 原生专用
        var now = new Date(date.replace(/-/g, "/")) // 当前日期
        var nowYear = now.getFullYear() //当前年
        var nowMonth = now.getMonth() //当前月 （值为0~11）
        var firstDay = new Date(nowYear, nowMonth, 1)  // 本月开始时间
        var LastDay = new Date(nowYear, nowMonth + 1, 0); // 本月结束时间
        return { state: firstDay.Format("yyyy-MM-dd"), end: LastDay.Format("yyyy-MM-dd") }
    }

    function timeFormat(items, config = true) {//  IOS专用 处理数据格式
        let itemsFormat = items.replace(/-/g, "/") || items
        var dd = new Date(itemsFormat)// 解决IOS不支持YYYY-MM-DD格式
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 <= 9 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1);
        var d = dd.getDate() <= 9 ? '0' + dd.getDate() : dd.getDate();

        var time = config ? `${y}-${m}-${d}` : `${y}-${m}`
        return time
    }
})(window, document, jQuery)